import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
import 'package:provider/provider.dart';
import 'package:chewie/chewie.dart';
import 'package:qaun_ni_dev/provider/brush_provider.dart';



class MyVideoPage extends StatefulWidget {
//  var videoStr;
//  BrushVideo(this.videoStr);


  @override
  _MyVideoPageState createState() => _MyVideoPageState();
}

class _MyVideoPageState extends State<MyVideoPage> {
  VideoPlayerController videoPlayerController;
  ChewieController chewieController;
  var tempData = '';

  @override
  void initState () {
    super.initState();
//    getVideoStr();
    myVideoControl();
  }


//  void getVideoStr() {
//    setState(() {
//      tempData = widget.videoStr;
//      print('aaaa>>>>>>${widget.videoStr}');
//    });
//  }

  void myVideoControl () {
    String url = Provider.of<BrushProvider>(context,listen: false).videoUrl;
    videoPlayerController = VideoPlayerController.network(url);
    chewieController = ChewieController(
      videoPlayerController: videoPlayerController,
      aspectRatio: 3 / 2, //宽高比
      autoPlay: true, //自动播放
      looping: true, //循环播放
    );
  }


  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: AppBar(
        title: Text('视频播放'),
      ),
      body: Container(
          child: Column(
            children: <Widget>[
              Container(
                height: 500,
                child: Chewie(
                  controller: chewieController,
                ),
              ),
            ],
          )
      ),
    );
  }


  @override
  void dispose() {
    /**
     * 当页面销毁的时候，将视频播放器也销毁
     * 否则，当页面销毁后会继续播放视频！
     */
    videoPlayerController.dispose();
    chewieController.dispose();
    super.dispose();
  }

}

